﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DANGQUYNHTRANG.Programming.Part03.Level1.BT01
{
    public partial class View : Form
    {
        public View()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();

            //Check ID is inputed or not
            if (string.IsNullOrEmpty(txtID.Text))
            {
                errorProvider1.SetError(txtID, "Please input ID");
                txtID.Focus();
            }
            else if (string.IsNullOrEmpty(txtPw.Text))
            {
                errorProvider1.SetError(txtPw, "Please input PW");
                txtPw.Focus();
            }
            else
            {
                //Khoi tao CONTROLER
                CONTROLER control = new CONTROLER();
                USERENTITY user = new USERENTITY();

                user.UserId = txtID.Text;
                user.UserPw = txtPw.Text;

                if (control.checkUser(user))
                    MessageBox.Show("Login Success!");
                else MessageBox.Show("Login Failed!");
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {   //1
            //this.Close();

            //2
            Application.Exit();
        }
    }
}
